package com.thinksoft.ui;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

/**
 * @author txf
 * @create 2020/3/25 0025
 * @
 */
public class ImmerseActivity extends AppCompatActivity {
    View rootLayout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置状态栏颜色为透明
        setStatusBarColor(this, 0x00000000);
        setContentView(R.layout.activity_immerse);
        rootLayout = findViewById(R.id.rootLayout);
        //内容根布局设置为true 让内容不被状态栏遮挡
        rootLayout.setFitsSystemWindows(true);


        findViewById(R.id.backButton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    /**
     * 设置状态栏 背景颜色
     */
    public void setStatusBarColor(Activity activity, int color) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            View decorView = activity.getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            if (option != decorView.getSystemUiVisibility()) {
                decorView.setSystemUiVisibility(option);
            }
            if (color != activity.getWindow().getStatusBarColor()) {
                activity.getWindow().setStatusBarColor(color);
            }
        }
    }
}
